﻿<UserControl x:Class="Samples.GasyTek.Lakana.Mvvm.VewModelProperties.SampleViewModelPropertyView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300"
             Loaded="UserControlLoaded">

    <UserControl.Resources>

        <Style x:Key="FieldTitleStyle"
               TargetType="TextBlock">
            <Setter Property="HorizontalAlignment" 
                    Value="Right" />
            <Setter Property="VerticalAlignment"
                    Value="Top" />
            <Setter Property="Margin" 
                    Value="0,0,5,0" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding HasChanged}"
                             Value="True">
                    <Setter Property="FontWeight"
                            Value="Bold" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>

    <Grid VerticalAlignment="Center"
          HorizontalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="30" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"
                              MinWidth="120" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="180" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="20" />
        </Grid.ColumnDefinitions>

        <!-- Age -->
        <TextBlock Text="{Binding Label}"
                   DataContext="{Binding Age}"
                   Style="{StaticResource FieldTitleStyle}" />
        <xctk:IntegerUpDown Grid.Column="2" 
                            Value="{Binding Age.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=False}"
                            AllowSpin="True" />
        <Image Grid.Column="4"
               RenderOptions.BitmapScalingMode="HighQuality"
               ToolTip="{Binding Age.Description}"
               Source="../Resources/info.png" />

        <!-- Country -->
        <TextBlock Grid.Row="2"
                   Text="{Binding Label}"
                   DataContext="{Binding Country}"
                   Style="{StaticResource FieldTitleStyle}" />
        <ComboBox Grid.Row="2"
                  Grid.Column="2"
                  ItemsSource="{Binding Country.ItemsSource}"
                  SelectedItem="{Binding Country.SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  DisplayMemberPath="Name" />
        <Image Grid.Row="2"
               Grid.Column="4"
               RenderOptions.BitmapScalingMode="HighQuality"
               ToolTip="{Binding Country.Description}"
               Source="../Resources/info.png" />

        <!-- Rank -->
        <TextBlock Grid.Row="4"
                   Text="{Binding Label}"
                   DataContext="{Binding Rank}"
                   Style="{StaticResource FieldTitleStyle}" />
        <ComboBox Grid.Row="4"
                  Grid.Column="2"
                  ItemsSource="{Binding Rank.ItemsSource}"
                  SelectedValue="{Binding Rank.SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  SelectedValuePath="Value"
                  DisplayMemberPath="Label" />
        <Image Grid.Row="4"
               Grid.Column="4"
               RenderOptions.BitmapScalingMode="HighQuality"
               ToolTip="{Binding Rank.Description}"
               Source="../Resources/info.png" />

        <!-- Save / Cancel buttons -->
        <Border Grid.Row="6" Grid.ColumnSpan="5">
            <StackPanel>
                <StackPanel HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Content="Save"
                            Width="120"
                            Command="{Binding SaveCommand}" />
                    <Button Content="Cancel"
                            Width="80"
                            Margin="6,0,0,0"
                            Command="{Binding CancelCommand}" />
                </StackPanel>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
